﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace UI.Forms
{
    public partial class Warehouse_N : FormBase1
    {
        public delegate void DoAction();//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        public delegate void Do(string warehouseID);//如果有参数的话，定义参数 

        public Do FatherRefresh1;
        public Warehouse_N()
        {
            InitializeComponent();
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            valildbefore();
            if (dxValidationProvider1.Validate())
            {
                SVC.client.Warehouse wh = new SVC.client.Warehouse();
                wh.WarehouseID = te_WarehouseID.Text;
                wh.WarehouseName = te_name.Text;
                wh.shopcode = lue_shop.EditValue.ToString();
                wh.Remarks = te_remarks.Text;
                string result = my.bw.Warehouse_Add(wh, my.ACID);
                if(string.IsNullOrWhiteSpace(result))
                {
                    reset();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }

        private void valildbefore()
        {
            te_WarehouseID.Text = te_WarehouseID.Text;
            te_name.Text = te_name.Text.Trim();
            te_remarks.Text = te_remarks.Text.Trim();
        }

        private void reset()
        {
            te_WarehouseID.Text = "";
            te_name.Text ="";
            lue_shop.EditValue = null;
            te_remarks.Text = "";
        }

        private void btn_nowclose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            valildbefore();
            if (dxValidationProvider1.Validate())
            {
                SVC.client.Warehouse wh = new SVC.client.Warehouse();
                wh.WarehouseID = te_WarehouseID.Text;
                wh.WarehouseName = te_name.Text;
                wh.shopcode = lue_shop.EditValue.ToString();
                wh.Remarks = te_remarks.Text;

                string result = my.bw.Warehouse_Add(wh, my.ACID);
                if (string.IsNullOrWhiteSpace(result))
                {
                    //FatherRefresh();
                    FatherRefresh1(wh.WarehouseID);
                    this.Close();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }

        private void Warehouse_N_Load(object sender, EventArgs e)
        {
            lue_shop.Properties.DataSource = my.bw.View_shop_lite_Get(my.ACID);
        }
    }
}